/**
 * A meeple has an owner (player)
 * A meeple has a type (knight, monk, farmer, thief or none)
 * A meeple has a pointer to it's global feature (or null) 
 * A meeple has a pointer to it's tile feature (or null)  (not necessary, i think, since all tile features are immediately part of a global feature)
 * A meeple has a pointer to it's tile (or null)
 * 
 * 
 * @author sam
 */
public class Meeple {
	
	/// Meeple types
	static final public int NONE = 0;
	static final public int KNIGHT = 1;
	static final public int MONK = 2;
	static final public int FARMER  = 3;
	static final public int THIEF = 4;
	
	public Player owner;
	public int type; // see Meeple types
	public GlobalFeature globalFeature;
	public Tile.Feature tileFeature;
	public Tile tile;
	public boolean used; // true if placed on the board, default is false
	
	public int x;	// pixel position relative to it's tile 
	public int y;	 
	
	public Meeple(Player owner)
	{
		this.owner = owner;		
		this.type = NONE;
		this.globalFeature = null;
		this.tileFeature = null;
		this.tile = null;
		this.x = 0;
		this.y = 0;
		this.used = false;
	}
	
	public void place(Tile tile, Tile.Feature feature, int x, int y)
	{
		this.used = true;
		this.tile = tile;
		//this.globalFeature = TODO
		this.tileFeature = feature;
		setType(feature.type);		
		setPosition(x,y);
		
		System.out.println(this.owner.name + " playing a " + Meeple.typeToString(this.type)+ "(" + this.type + ") on tile " + Tile.typeToString(feature.type) + "(" + feature.type + ") at " + x + "," + y);
	}
	
	public void setPosition(int x, int y)
	{
		this.x = x;
		this.y = y; 
	}

	public void setType(int featureType)
	{
		if (featureType==Tile.CITY) this.type = Meeple.KNIGHT;
		else if (featureType==Tile.CLOISTER) this.type = Meeple.MONK;
		else if (featureType==Tile.FARM) this.type = Meeple.FARMER;
		else if (featureType==Tile.ROAD) this.type = Meeple.THIEF;
		else this.type = Meeple.NONE; // shouldn't get here!
	}
	
	static public String typeToString(int type)
	{
		if (type==Meeple.KNIGHT) return "Knight";
		else if (type==Meeple.MONK) return "Monk";
		else if (type==Meeple.FARMER) return "Farmer";
		else if (type==Meeple.THIEF) return "Thief";
		else return "Unknown";
	
	}
	
	/**
	 * When drawn, the tile with this meeple will draw it so the position is relative...
	 */
	public void draw()
	{
	}
}
